export const composeValidators =
  (...validators) =>
  value =>
    validators.reduce((error, validator) => error || validator(value), undefined);

export const required = value => (!!value || value === false ? undefined : '必填');

export const mustNumber = value =>
  value === '' || value === null || (value && isNaN(value) === false) ? undefined : '必须是数字';

export const numberLength = length => value =>
  value === '' || value === null || (value && isNaN(value) === false && value.length === length)
    ? undefined
    : `数字长度是${length}`;

export const chartLength = length => value => value && value.length === length ? undefined : `长度必须是${length}`;
